const apiURL = 'https://api.breadtrip.com';

const trip = {
	hot(data,callback){
		wx.request({
			url: `${apiURL}/v2/index/`,
			method: 'GET',
			data,
			header:{
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	},
	waypoint(tripId,callback){
		wx.request({
			url: `${apiURL}/trips/${tripId}/waypoints/`,
			method: 'GET',
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	}
}

const viewWaypoint = {
	detail(tripId,waypointId,callback){
		wx.request({
			url: `${apiURL}/trips/${tripId}/waypoints/${waypointId}/`,
			method: 'GET',
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	},
	replies(tripId, waypointId, callback){
		wx.request({
			url: `${apiURL}/trips/${tripId}/waypoints/${waypointId}/replies/`,
			method: 'GET',
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	}
}

const user = {
	userInfo(userId,callback){
		wx.request({
			url: `${apiURL}/users/${userId}/v2/`,
			method: 'GET',
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		});
	}
}

const destination = {
	list(callback){
		wx.request({
			url: `${apiURL}/destination/v3/`,
			method: 'GET',
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	},
	place(typ,placeId,callback){
		wx.request({
			url: `${apiURL}/destination/place/${typ}/${placeId}/`,
			method: 'GET',
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	},
	attractions(typ, id, poiType, data, callback){
		let poi = poiType ? `${poiType}/` : 'all/' ;
		wx.request({
			url: `${apiURL}/destination/place/${typ}/${id}/pois/${poi}`,
			method: 'GET',
			data,
			header: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			},
			success(res) {
				callback('success', res);
			},
			fail(res) {
				callback('fail', res);
			},
			complete(res) {
				callback('complete', res);
			}
		})
	}
}

module.exports = {
	trip,
	viewWaypoint,
	user,
	destination
}